#pragma once

#include <arpa/inet.h>
#include <string>

// 封装socket地址类
class InetAddress
{
public:
    explicit InetAddress(uint16_t port = 0, std::string ip = "127.0.0.1");
    explicit InetAddress(struct sockaddr_in addr);

    std::string toIp() const;
    std::string toIpPort() const;
    uint16_t toport() const;

    void setSockAddr(const sockaddr_in &addr) { addr_ = addr; }
    const struct sockaddr_in *getSockAddr() const { return &addr_; }

private:
    struct sockaddr_in addr_;
};